﻿
if (typeof NTTHAO == "undefined" || !NTTHAO) {
    /**
     * The NTTHAO global namespace object.  If NTTHAO is already defined, the
     * existing NTTHAO object will not be overwritten so that defined
     * namespaces are preserved.
     * @class NTTHAO
     * @static
     */
    var NTTHAO = {};
}

/**
 * Returns the namespace specified and creates it if it doesn't exist
 * <pre>
 * NTTHAO.namespace("property.package");
 * NTTHAO.namespace("NTTHAO.property.package");
 * </pre>
 * Either of the above would create NTTHAO.property, then
 * NTTHAO.property.package
 *
 * Be careful when naming packages. Reserved words may work in some browsers
 * and not others. For instance, the following will fail in Safari:
 * <pre>
 * NTTHAO.namespace("really.long.nested.namespace");
 * </pre>
 * This fails because "long" is a future reserved word in ECMAScript
 *
 * @method namespace
 * @static
 * @param  {String*} arguments 1-n namespaces to create 
 * @return {Object}  A reference to the last namespace object created
 */
NTTHAO.namespace = function() {
    var a=arguments, o=null, i, j, d;
    for (i=0; i<a.length; i=i+1) {
        d=a[i].split(".");
        o=NTTHAO;

        // NTTHAO is implied, so it is ignored if it is included
        for (j=(d[0] == "NTTHAO") ? 1 : 0; j<d.length; j=j+1) {
            o[d[j]]=o[d[j]] || {};
            o=o[d[j]];
        }
    }

    return o;
};

NTTHAO.extend = function(o, aArgs) {
    if ((!NTTHAO.lang.isArgs(aArgs) && !NTTHAO.lang.isArray(aArgs)) || aArgs.length < 1) return o;
    var a, b, c, d, f, g, h, i = aArgs[0] || {}, j = 1, k = aArgs.length, l = !1, e=NTTHAO.lang;
    typeof i == "boolean" && (l = i, i = aArgs[1] || {}, j = 2), typeof i != "object" && !e.isFunction(i) && (i = {}), k === j && (i = o, --j);
    for (; j < k; j++)
        if ((a = aArgs[j]) != null)
            for (c in a) {
                d = i[c], f = a[c];
                if (i === f)
                    continue;
                l && f && (e.isPlainObject(f) || (g = e.isArray(f))) ? (g ? (g = !1, h = d && e.isArray(d) ? d : []) : h = d && e.isPlainObject(d) ? d : {}, i[c] = NTTHAO.extend(o, [l, h, f])) : f !== b && (i[c] = f)
            }
    return i;
};
        
/**
 * namespace NTTHAO.lang
 */
NTTHAO.namespace('lang');
NTTHAO.lang.type = function(G){return typeof(G);}
NTTHAO.lang.isArray=function(G){return Object.prototype.toString.apply(G)==="[object Array]";}
NTTHAO.lang.isArgs=function(G){return Object.prototype.toString.apply(G)==="[object Arguments]";}
NTTHAO.lang.isBoolean=function(G){return typeof G==="boolean";}
NTTHAO.lang.isFunction=function(G){return Object.prototype.toString.apply(G)==="[object Function]";}
NTTHAO.lang.isNull=function(G){return G===null;}
NTTHAO.lang.isNumber=function(G){return typeof G==="number"&&isFinite(G);}
NTTHAO.lang.isString=function(G){return typeof G==="string";}
NTTHAO.lang.isUndefined=function(G){return typeof G==="undefined";}
NTTHAO.lang.isObject=function(G) {return (G&&(typeof G==="object"||NTTHAO.lang.isFunction(G)))||false;}
NTTHAO.lang.isWindow = function(G){return G && typeof G=="object" && "setInterval" in G; }
NTTHAO.lang.isPlainObject = function(a) {
    var e = NTTHAO.lang;
    var D = Object.prototype.hasOwnProperty;
    if (!a || e.type(a) !== "object" || a.nodeType || e.isWindow(a))
        return !1;
    try {
        if (a.constructor && !D.call(a, "constructor") && !D.call(a.constructor.prototype, "isPrototypeOf"))
            return !1;
    } catch (c) {
        return !1;
    }
    var d;
    for (d in a);
    return d === b || D.call(a, d);
}
NTTHAO.lang.isEmptyObject = function(a) { for (var b in a) return !1; return !0; }


/**
 * namespace NTTHAO.util
 */
NTTHAO.namespace('util');
NTTHAO.util.getElement = function(el) {
    if(!NTTHAO.lang.isObject(el)) {
        return document.getElementById(el);
    }
    return el;
}

NTTHAO.util.getAbsoluteXY = function(el) {
    if(!NTTHAO.lang.isObject(el)) {
        el = document.getElementById(el);
    }
    if(el == null) {
        return null;
    }
    
    var yPos = el.offsetTop;
    var xPos = el.offsetLeft;
    var tempEl = el.offsetParent;
    while (tempEl != null) {
        xPos += tempEl.offsetLeft;
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }

    return [xPos, yPos];
}

NTTHAO.util.includeJS = function(jsPath){
    var script = document.createElement("script");
    script.setAttribute("type", "text/javascript");
    script.setAttribute("src", jsPath);
    document.getElementsByTagName("head")[0].appendChild(script);
}

/**
 * string functions
 */
if (!String.prototype.trim) {
    String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g, "");};
}
if (!String.prototype.ltrim) {
    String.prototype.ltrim=function(){return this.replace(/^\s+/,'');}
}
if (!String.prototype.rtrim) {
    String.prototype.rtrim=function(){return this.replace(/\s+$/,'');}
}
if (!String.prototype.fulltrim) {
    String.prototype.fulltrim=function(){return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,'').replace(/\s+/g,' ');}
}
if (!String.prototype.replaceAll) {
    String.prototype.replaceAll=function(searchvalue,newvalue,insensitive) {
        if (insensitive) {
            return this.replace(new RegExp(searchvalue, 'gi'),newvalue);
        } else {
            return this.replace(new RegExp(searchvalue, 'g'),newvalue);
        }
    }
}

if (!String.prototype.toVNPrice) {
    String.prototype.toVNPrice = function() {
        var res = '';
        var index = this.length - 3;
        while (index > 0) {
            res = '.' + this.substr(index, 3) + res;
            index -= 3;
        }
        if (index > -3) {
            res = this.substr(0, 3 + index) + res;
        } else if (res.length > 0) {
            res = res.substr(1);
        }
        return res;
    }
}
if (!Number.prototype.toVNPrice) {
    Number.prototype.toVNPrice = function() {
        return this.toString().toVNPrice();
    }
}